#pragma once

#include <AVUIContentControl.h>

namespace AVUI {
class RoutedCommand;

class ButtonBase : public ContentControl
{
public:
    ButtonBase() : m_isSpaceKeyDown(false) { };
    ~ButtonBase() { };

    DECLARE_ELEMENT(ButtonBase, ContentControl);

    DECLARE_READONLY_DEPENDENCY_PROPERTY(IsPressed);
    bool get_IsPressed() { return AVUI::UnboxValue<bool>(GetValue(get_IsPressedProperty())); }

    DECLARE_DEPENDENCY_PROPERTY(Command);
    TRefCountedPtr<RoutedCommand> get_Command() { return (RoutedCommand*)(Object*)GetValue(get_CommandProperty()); }
    void set_Command(RoutedCommand* pValue) { SetValue(get_CommandProperty(), (Object*)pValue); } 

    DECLARE_DEPENDENCY_PROPERTY(CommandParameter);
    TRefCountedPtr<Object> get_CommandParameter() { return GetValue(get_CommandParameterProperty()); }
    void set_CommandParameter(Object* pValue) { SetValue(get_CommandParameterProperty(), pValue); } 

    DECLARE_DEPENDENCY_PROPERTY(CommandTarget);
    TRefCountedPtr<Object> get_CommandTarget() { return GetValue(get_CommandTargetProperty()); }
    void set_CommandTarget(Object* pValue) { SetValue(get_CommandTargetProperty(), pValue); } 

    DECLARE_DEPENDENCY_PROPERTY(ClickMode);
    ClickMode::Enum get_ClickMode() { return (ClickMode::Enum)(AVUI::UnboxValue<int>(GetValue(get_ClickModeProperty()))); }
    void set_ClickMode(ClickMode::Enum value) { SetValue(get_ClickModeProperty(), AVUI::BoxValue<int>(value)); } 

    IMPLEMENT_ROUTED_EVENT(Click, RoutedEventArgs, RoutingStrategy::Bubble);


protected:

    void set_IsPressed(bool value) { return SetValue(get_IsPressedPropertyKey(), BoxValue(value)); }
    virtual void OnMouseLeftButtonDown(MouseButtonEventArgs* pArgs);
    virtual void OnMouseLeftButtonUp(MouseButtonEventArgs* pArgs);
    virtual void OnMouseEnter(MouseEventArgs* pArgs);
    virtual void OnMouseLeave(MouseEventArgs* pArgs);
    virtual void OnMouseMove(MouseEventArgs* pArgs);
    virtual void OnLostMouseCapture(MouseEventArgs* pArgs);

    virtual void OnKeyUp(KeyEventArgs* pArgs);
    virtual void OnKeyDown(KeyEventArgs* pArgs);

    virtual void OnClick();
    virtual void OnIsPressedChanged(DependencyPropertyChangedEventArgs* pArgs) { }

private:
    static void StaticConstructor();
    static void OnIsPressedChanged(DependencyObject* pDO, DependencyPropertyChangedEventArgs* e) { ((ButtonBase*)pDO)->OnIsPressedChanged(e); }
    bool GetMouseLeftButtonReleased();
    bool HandleIsMouseOverChanged();   
    bool get_IsSpaceKeyDown() const { return m_isSpaceKeyDown; }
    void set_IsSpaceKeyDown(bool isSpaceKeyDown) { m_isSpaceKeyDown = isSpaceKeyDown; }

    void SetIsPressed(bool pressed);
    void UpdateIsPressed();

    bool m_isSpaceKeyDown;

};


}; // namespace AVUI
